package com.zwps.biz.controller.http;

import com.zwps.biz.domain.service.FileManageService;
import com.zwps.biz.domain.service.FileRecordService;
import com.zwps.biz.api.model.dto.file.record.SelectFileRecordDTO;
import com.zwps.biz.api.model.dto.file.record.UpdateFileRecordDTO;
import com.zwps.biz.api.model.vo.file.FileUploadInfoVO;
import com.zwps.biz.api.model.vo.file.record.FileRecordVO;
import com.zwps.biz.api.model.vo.file.record.FileVO;
import com.zwps.common.controller.response.message.ResponseDataPageMessage;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 文件记录
 * 
 * @ClassName: FileRecordController
 * @Description:
 * @author lyh
 * @date 2023年5月27日 下午9:19:20
 *
 */
@Tag(name = "文件记录")
@RestController
@RequestMapping("file/record")
@AllArgsConstructor
@Validated
public class FileRecordController {

    private FileRecordService fileRecordService;

    private FileManageService fileManageService;

    @Operation(summary = "分页查询文件记录")
    @GetMapping("page")
    public ResponseDataPageMessage<FileRecordVO> selectFileRecordPage(SelectFileRecordDTO dto) {
        return ResponseDataPageMessage.data(fileRecordService.selectFileRecords(dto));
    }

    @Operation(summary = "删除多文件记录，文件异步删除")
    @DeleteMapping("multi/{ids}")
    public void deleteFileRecords(@Valid @NotBlank @PathVariable String ids) {
        fileRecordService.deleteFileRecords(ids);
    }

    @Operation(summary = "删除单文件记录，文件同步删除")
    @DeleteMapping("{id}")
    public void deleteFileRecord(@Valid @NotBlank @PathVariable String id) {
        fileRecordService.deleteFileRecord(id);
    }

    /**
     * 查询文件记录根据文件id
     * @Title: selectFileByFileId
     * @Description:
     * @param id
     * @returnFileVO
     * @author cg
     * @date 2023年9月9日 下午14:44:47
     */
    @GetMapping(value = "{id}")
    FileVO selectFileByFileId(@Valid @NotBlank @PathVariable String id ){
        return fileRecordService.selectFileByFileId(id);
    }

    @Parameter(name = "id", description = "文件记录主键ID", in = ParameterIn.PATH)
    @Operation(summary = "文件记录-修改")
    @PutMapping("{id}")
    public void updateFileRecord(@Valid @NotBlank @PathVariable String id,
                                    @Valid @NotNull @RequestBody UpdateFileRecordDTO dto) {
        fileRecordService.updateFileRecord(id, dto);
    }

    @Operation(summary = "文件记录-新增")
    @PostMapping()
    public FileUploadInfoVO addFileRecord(@Valid @NotNull MultipartFile file,
                                          @Valid @NotBlank String fileName,
                                          @Valid  String fileUrl,
                                          @Valid @NotNull Integer externalFile) {
        return fileManageService.addFileRecord(file, fileName, fileUrl, externalFile);
    }
}
